package hlhj.fhp.newslib.adapters

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.net.Uri
import android.support.v4.view.ViewPager
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.widget.*
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.shuyu.gsyvideoplayer.utils.GSYVideoHelper
import com.shuyu.gsyvideoplayer.utils.OrientationUtils
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer
import com.shuyu.gsyvideoplayer.video.base.GSYVideoView
import ezy.ui.view.BannerView
import hlhj.fhp.newslib.R
import hlhj.fhp.newslib.activitys.ImageInfoAty
import hlhj.fhp.newslib.activitys.SpecialDetailAty
import hlhj.fhp.newslib.activitys.SpecialInfoAty
import hlhj.fhp.newslib.javabean.CatBean
import hlhj.fhp.newslib.utils.GlideUtil
import java.util.ArrayList
import com.tenma.ventures.bean.utils.TMSharedPUtil
import com.tenma.ventures.config.TMServerConfig
import com.tenma.ventures.share.bean.TMLinkShare
import com.tenma.ventures.share.util.TMShareUtil
import hlhj.fhp.newslib.Constant
import hlhj.fhp.newslib.network.Urls
import org.apache.cordova.LOG
import tmproject.hlhj.fhp.adplayerhelper.AdHelper

/**
 * Created by Administrator on 2018\6\26 0026.
 */
class CatMultiAdp(multiDatas:ArrayList<CatBean.DataBean.ListBeanX>,private val activity: Activity) :BaseMultiItemQuickAdapter<CatBean.DataBean.ListBeanX,BaseViewHolder>(multiDatas) {
    private var cp:Long=0
    private var testUrl="http://tianma.wufenhuyu.com/dist2/test/movie.mp4"
    init {
        addItemType(5, R.layout.recomment_headpager)//头部banner
        addItemType(6, R.layout.recommend_active)//活动
        addItemType(1, R.layout.recommend_news)//新闻
        addItemType(2, R.layout.recommend_video)//视频
        addItemType(4, R.layout.recommend_adv)//广告
        addItemType(3, R.layout.recommend_article)//图片
    }
    override fun convert(helper: BaseViewHolder?, item: CatBean.DataBean.ListBeanX?) {
        when(helper?.itemViewType){
            1->{
                val loImg = helper?.getView<LinearLayout>(R.id.loimg)
                val img1 = helper?.getView<ImageView>(R.id.img1)
                val img2 = helper?.getView<ImageView>(R.id.img2)
                val img3 = helper?.getView<ImageView>(R.id.img3)
                if (item!!.extract_img==null){
                    loImg.visibility=View.GONE
                }else{
                    /*if (item!!.extract_img[0]!=null) {
                        if (item?.extract_img[0]?.contains("http")!!){
                            Glide.with(mContext).load(item?.extract_img?.get(0))
                                    .apply(GlideUtil.loadIMGOption())
                                    .into(helper?.getView(R.id.img1)!!)
                        }else{
                            Glide.with(mContext).load(Urls.Base_URL+item?.extract_img?.get(0))
                                    .apply(GlideUtil.loadIMGOption())
                                    .into(helper?.getView(R.id.img1)!!)
                        }
                    }*/

                    Log.i("fhh","宽${img1.measuredWidth}高${img1.measuredHeight}")
                    when(item!!.extract_img.size){
                        0->{
                            loImg.visibility= View.GONE
                        }
                        1->{

                            helper?.setVisible(R.id.dv1,false)
                            helper?.setVisible(R.id.dv2,false)
                            val params = loImg.layoutParams as RelativeLayout.LayoutParams
                            params.height=dp2px(mContext,150f)
                            loImg.layoutParams=params
                            if (item!!.extract_img[0]!=null) {
                                if (item?.extract_img[0].contains("http")){
                                    Glide.with(mContext).load(item?.extract_img?.get(0))
                                            .apply(GlideUtil.loadIMGOption())
                                            .into(img1)
                                }else{
                                    Glide.with(mContext).load(Urls.Base_URL+item?.extract_img?.get(0))
                                            .apply(GlideUtil.loadIMGOption())
                                            .into(img1)
                                }

                            }
                            loImg.visibility= View.VISIBLE
                            img1.visibility= View.VISIBLE
                            img2.visibility= View.GONE
                            img3.visibility= View.GONE
                        }
                        2->{
                            helper?.setVisible(R.id.dv1,false)
                            helper?.setVisible(R.id.dv2,false)
                            val params = loImg.layoutParams as RelativeLayout.LayoutParams
                            params.height=dp2px(mContext,150f)
                            loImg.layoutParams=params
                            if (item!!.extract_img[0]!=null) {
                                Glide.with(mContext).load(Urls.Base_URL+item?.extract_img?.get(0))
                                        .apply(GlideUtil.loadIMGOption())
                                        .into(img1)
                            }
                            if (item!!.extract_img[1]!=null) Glide.with(mContext).load(Urls.Base_URL+item?.extract_img?.get(1))
                                    .apply(GlideUtil.loadIMGOption())
                                    .into(img2)
                            loImg.visibility= View.VISIBLE
                            img1.visibility= View.VISIBLE
                            img2.visibility= View.VISIBLE
                            img3.visibility= View.GONE
                        }
                        else->{
                            helper?.setVisible(R.id.dv1,true)
                            helper?.setVisible(R.id.dv2,true)
                            val params = loImg.layoutParams as RelativeLayout.LayoutParams
                            params.height=dp2px(mContext,70f)
                            loImg.layoutParams=params
                            if (item!!.extract_img[0]!=null) Glide.with(mContext).load(Urls.Base_URL+item?.extract_img?.get(0))
                                    .apply(GlideUtil.loadIMGOption())
                                    .into(img1)
                            if (item!!.extract_img[1]!=null) Glide.with(mContext).load(Urls.Base_URL+item?.extract_img?.get(1))
                                    .apply(GlideUtil.loadIMGOption())
                                    .into(img2)
                            if (item!!.extract_img[2]!=null) Glide.with(mContext).load(Urls.Base_URL+item?.extract_img?.get(2))
                                    .apply(GlideUtil.loadIMGOption())
                                    .into(img3)

                            loImg.visibility= View.VISIBLE
                            img1.visibility= View.VISIBLE
                            img2.visibility= View.VISIBLE
                            img3.visibility= View.VISIBLE
                        }
                    }
                }

                helper?.setText(R.id.itemAuther,item?.release)
                helper?.setText(R.id.itemHis,"浏览量:${item?.click_rate}")
                helper?.setText(R.id.itemTime,item?.add_time)
                helper?.setText(R.id.itemTittle,item?.title)
                helper?.itemView.setOnClickListener {
                    data[helper?.adapterPosition].click_rate=data[helper?.adapterPosition].click_rate+1
                    notifyDataSetChanged()
                    val intent = Intent(mContext, SpecialInfoAty::class.java)
                    intent.putExtra("id",item?.id)
                    if (item!!.extract_img.size>0){
                        intent.putExtra("thumb",item?.extract_img[0].toString())
                    }else{
                        intent.putExtra("thumb","https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1531470814752&di=49e3232f35fa9c8439160a2d071bf1cb&imgtype=0&src=http%3A%2F%2Fimg382.ph.126.net%2Fp4dMCiiHoUGxf2N0VLspkg%3D%3D%2F37436171903673954.jpg")
                    }
                    mContext.startActivity(intent)
                }
                val btShare = helper?.getView<ImageView>(R.id.btShare)

                btShare.setOnClickListener {
                    val tmLinkShare = TMLinkShare()
                    tmLinkShare.title=item?.title
                    tmLinkShare.url=TMServerConfig.BASE_URL+"/application/hlhj_news/asset/article.html?id=${item.id}"
//                    tmLinkShare.url="http://mx.360tianma.com"+"/application/hlhj_news/asset/article.html?id=${item.id}"
                    tmLinkShare.description=item?.title
                    tmLinkShare.thumb=item?.extract_img[0].toString()
                    TMShareUtil.getInstance(mContext).shareLink(tmLinkShare)

                }
                /*                val bannerView = helper?.getView<BannerView<String>>(R.id.banner)
                                bannerView.setViewFactory { item, position, container ->
                                    val imageView = ImageView(container.context)
                                    Glide.with(mContext).load(item).into(imageView)
                                    imageView
                                }
                                val imgDatas=ArrayList<String>()
                                for (i in 0..item?.data_img!!.size-1){
                                    imgDatas.add(item?.data_img[i].cover_img)
                                }

                                bannerView.setDataList(imgDatas)
                                bannerView.start()*/
            }
            2->{

                helper?.setText(R.id.itemTittle,item?.title)
                helper?.setText(R.id.itemAuther,item?.release)
                helper?.setText(R.id.itemTime,item?.add_time)
                helper?.setText(R.id.itemHis,"浏览量：${item?.click_rate}")


                val gsyPlayer = helper?.getView<StandardGSYVideoPlayer>(R.id.videoPlayer)
                gsyPlayer.backButton.visibility= View.GONE
                /*播放器*/
                val builder = GSYVideoHelper.GSYVideoHelperBuilder()
                Log.e("fhp",item?.video_url)
                builder
                        .setIsTouchWiget(true)
                        .setVideoTitle("")
                        .setRotateViewAuto(false)
                        .setAutoFullWithSize(true)
                        .setUrl(item?.video_url?.replace("\\","/"))
                        .build(gsyPlayer)
                val imageView = ImageView(mContext)
                Glide.with(mContext).load(item?.video_cover).apply(GlideUtil.loadIMGOption())
                        .into(imageView)
                gsyPlayer.thumbImageView=imageView
                AdHelper.setAdPlayer(mContext,gsyPlayer,helper?.itemView as ViewGroup,Constant.ads,0.7f,0.8f)

                val btShare = helper?.getView<ImageView>(R.id.btShare)

                btShare.setOnClickListener {
                    val tmLinkShare = TMLinkShare()
                    tmLinkShare.title=item?.title
//                    tmLinkShare.url="http://mx.360tianma.com"+"/application/hlhj_news/asset/article.html?id=${item?.id}"
                    tmLinkShare.url=TMServerConfig.BASE_URL+"/application/hlhj_news/asset/article.html?id=${item?.id}"

                    tmLinkShare.description=item?.title
                    tmLinkShare.thumb=item?.video_cover
                    TMShareUtil.getInstance(mContext).shareLink(tmLinkShare)

                }
            }
            3->{
                val his = helper?.getView<TextView>(R.id.itemHis)
                Glide.with(mContext)
                        .load(item?.atlas_img!![0])
                        .apply(GlideUtil.loadIMGOption())
                        .into(helper?.getView(R.id.img)!!)
                helper.setText(R.id.itemTittle,item?.title)
                helper?.setText(R.id.imgsNum,"${item?.atlas_img!!.size}图")
                helper?.setText(R.id.itemAuther,item?.release)
                his.text="浏览量:${item?.click_rate}"
                helper?.setText(R.id.itemTime,item?.add_time)
                val lo = helper.getView<RelativeLayout>(R.id.layout)
                lo.setOnClickListener {
                    val intent = Intent(mContext, ImageInfoAty::class.java)
                    val imgs = ArrayList<String>()
                    imgs.addAll(item?.atlas_img)
                    intent.putExtra("imgs",imgs)
                    intent.putExtra("id",item?.id)
                    intent.putExtra("tittle",item?.title)
                    intent.putExtra("content",item?.content)
                    his.text="浏览量:${his.text.split(":")[1].toString().toInt()+1}"
                    mContext!!.startActivity(intent)
                }
                val btShare = helper?.getView<ImageView>(R.id.btShare)

                btShare.setOnClickListener {
                    val tmLinkShare = TMLinkShare()
                    tmLinkShare.title=item?.title
                    tmLinkShare.url=TMServerConfig.BASE_URL+"/application/hlhj_news/asset/atlas.html?id=${item?.id}"
//                    tmLinkShare.url="http://mx.360tianma.com"+"/application/hlhj_news/asset/atlas.html?id=${item?.id}"
                    tmLinkShare.description=item?.title
                    if (item?.atlas_img!=null){
                        tmLinkShare.thumb=item?.atlas_img[0].toString()
                    }
                    TMShareUtil.getInstance(mContext).shareLink(tmLinkShare)

                }
            }
            4->{
                val loImg = helper?.getView<LinearLayout>(R.id.loimg)
                val img1 = helper?.getView<ImageView>(R.id.img1)
                val img2 = helper?.getView<ImageView>(R.id.img2)
                val img3 = helper?.getView<ImageView>(R.id.img3)
                if (item!!.advertisement_img[0]!=null) Glide.with(mContext).load(Urls.Base_URL+item?.advertisement_img?.get(0))
                        .apply(GlideUtil.loadIMGOption())
                        .into(helper?.getView(R.id.img1)!!)
                Log.i("fhh",item?.extract_img.size.toString())
                when(item!!.extract_img.size){
                    0->{
                        loImg.visibility= View.GONE
                    }
                    1->{
                        if (item!!.advertisement_img[0]!=null) Glide.with(mContext).load(Urls.Base_URL+item?.advertisement_img?.get(0))
                                .apply(GlideUtil.loadIMGOption())
                                .into(img1)
                        loImg.visibility= View.VISIBLE
                        img1.visibility= View.VISIBLE
                        img2.visibility= View.GONE
                        img3.visibility= View.GONE
                    }
                    2->{
                        if (item!!.advertisement_img[0]!=null) Glide.with(mContext).load(Urls.Base_URL+item?.advertisement_img?.get(0))
                                .apply(GlideUtil.loadIMGOption())
                                .into(img1)
                        if (item!!.advertisement_img[1]!=null) Glide.with(mContext).load(Urls.Base_URL+item?.advertisement_img?.get(1))
                                .apply(GlideUtil.loadIMGOption())
                                .into(img2)
                        loImg.visibility= View.VISIBLE
                        img1.visibility= View.VISIBLE
                        img2.visibility= View.VISIBLE
                        img3.visibility= View.GONE
                    }
                    else->{
                        if (item!!.advertisement_img[0]!=null) Glide.with(mContext).load(Urls.Base_URL+item?.advertisement_img?.get(0))
                                .apply(GlideUtil.loadIMGOption())
                                .into(img1)
                        if (item!!.advertisement_img[1]!=null) Glide.with(mContext).load(Urls.Base_URL+item?.advertisement_img?.get(1))
                                .apply(GlideUtil.loadIMGOption())
                                .into(img2)
                        if (item!!.advertisement_img[2]!=null) Glide.with(mContext).load(Urls.Base_URL+item?.advertisement_img?.get(2))
                                .apply(GlideUtil.loadIMGOption())
                                .into(img3)

                        loImg.visibility= View.VISIBLE
                        img1.visibility= View.VISIBLE
                        img2.visibility= View.VISIBLE
                        img3.visibility= View.VISIBLE
                    }
                }
                helper.setText(R.id.itemTittle,item?.title)
                helper?.setText(R.id.tvOwner,item?.release)
                helper?.itemView.setOnClickListener {

                    val uri = Uri.parse(item?.advertisement_url)
                    val intent = Intent(Intent.ACTION_VIEW, uri)
                    mContext.startActivity(intent)
                }
            }
            5->{
                val bannerView = helper?.getView<BannerView<CatBean.DataBean.ListBeanX.DataImgBean>>(R.id.banner)
                bannerView.setViewFactory { i, position, container ->
                    val imageView = ImageView(container.context)
                    imageView.setBackgroundColor(Color.parseColor("#f0eff5"))
                    imageView.scaleType=ImageView.ScaleType.FIT_XY
                    val it = i as CatBean.DataBean.ListBeanX.DataImgBean
                    if (null!=it&&null!=it.cover_img){
                        if (it.cover_img.contains("http")){
                            Glide.with(mContext).load(it.cover_img).into(imageView)
                        }else{
                            Glide.with(mContext).load(Urls.Base_URL+it.cover_img).into(imageView)
                        }
                        imageView.setOnClickListener {
                            val intent = Intent(mContext, SpecialInfoAty::class.java)
                            intent.putExtra("id",i?.id)
                            intent.putExtra("thumb",i?.cover_img)
                            mContext.startActivity(intent)
                        }
                    }
                    imageView
                }
                if (null!=item?.data_img){
                    val imgDatas=ArrayList<CatBean.DataBean.ListBeanX.DataImgBean>()
                    for (i in 0..item?.data_img!!.size-1){
                        imgDatas.add(item?.data_img[i])
                    }
                    if (item?.data_img.size!=0){
                        item?.data_img[0].title?.let {
                            helper?.setText(R.id.itemTittle,it)
                        }
                    }
                    bannerView.setDataList(imgDatas)
                    bannerView.start()
                }
                bannerView.viewPager.addOnPageChangeListener(object :ViewPager.OnPageChangeListener{
                    override fun onPageScrollStateChanged(state: Int) {
                    }

                    override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
                    }

                    override fun onPageSelected(position: Int) {
                        item?.data_img?.get(position)?.title?.let {
                            helper?.setText(R.id.itemTittle,it)
                        }
                    }
                })


            }
            6->{
                /*颜色适配*/
                val tvL = helper?.getView<TextView>(R.id.tvl)
                val tvR = helper?.getView<TextView>(R.id.tvr)
                val dv = helper?.getView<TextView>(R.id.dvlr)
                if (null!= TMSharedPUtil.getTMThemeColor(mContext)&& TMSharedPUtil.getTMThemeColor(mContext).length>0){
                    tvL.setBackgroundColor(Color.parseColor(TMSharedPUtil.getTMThemeColor(mContext)))
                    tvR.setBackgroundColor(Color.parseColor(TMSharedPUtil.getTMThemeColor(mContext)))
                }
                if (item?.subject!=null){
                    if (item?.subject.size==1){
                        dv.visibility=View.GONE
                        tvR.visibility=View.GONE
                        tvL.text=item!!.subject[0].subject_name!!
                        tvL.setOnClickListener {
                            val intent = Intent(mContext, SpecialDetailAty::class.java)
                            intent.putExtra("id",item!!.subject[0].id)
                            intent.putExtra("tittle",item?.subject[0].subject_name)
                            mContext.startActivity(intent)
                        }
                    }else if (item?.subject.size>1){
                        dv.visibility=View.VISIBLE
                        tvR.visibility=View.VISIBLE
                        tvL.text=item!!.subject[0].subject_name!!
                        tvL.setOnClickListener {
                            val intent = Intent(mContext, SpecialDetailAty::class.java)
                            intent.putExtra("id",item!!.subject[0].id)
                            intent.putExtra("tittle",item?.subject[0].subject_name)
                            mContext.startActivity(intent)
                        }
                        tvR.text=item!!.subject[1].subject_name!!

                        tvR.setOnClickListener {
                            val intent = Intent(mContext, SpecialDetailAty::class.java)
                            intent.putExtra("id",item!!.subject[1].id)
                            intent.putExtra("tittle",item?.subject[1].subject_name)
                            mContext.startActivity(intent)
                        }
                    }
                }else{
                    dv.visibility=View.GONE
                    tvR.visibility=View.GONE
                    tvL.visibility=View.GONE
                }

                /*条目适配器*/
                val recyclerView = helper?.getView<RecyclerView>(R.id.recyclerview)
                val adp =object :BaseQuickAdapter<CatBean.DataBean.ListBeanX.ListBean,BaseViewHolder>(R.layout.recomment_active_item,item?.list){
                    override fun convert(helper: BaseViewHolder?, item: CatBean.DataBean.ListBeanX.ListBean?) {
                        helper?.setImageResource(R.id.itemImg,R.drawable.ic_launcher)
                        helper?.setText(R.id.itemTittle,item?.subject_name)
                        val tv_1 = helper?.getView<TextView>(R.id.tv_1)
                        if (null!= TMSharedPUtil.getTMThemeColor(mContext)&& TMSharedPUtil.getTMThemeColor(mContext).length>0){
                            tv_1!!.setBackgroundColor(Color.parseColor(TMSharedPUtil.getTMThemeColor(mContext)))
                        }
                        if (item?.cover_img?.contains("http")!!){
                            Glide.with(mContext).load(item?.cover_img).apply(GlideUtil.loadIMGOption())
                                    .into(helper?.getView(R.id.itemImg)!!)
                        }else{
                            Glide.with(mContext).load(Urls.Base_URL+"/"+item?.cover_img).apply(GlideUtil.loadIMGOption())
                                    .into(helper?.getView(R.id.itemImg)!!)
                        }

                        helper?.setText(R.id.itemAuther,item?.release)
                        helper?.setText(R.id.itemHis,"浏览量：${item?.click_rate}")
                        if (item?.is_hot==1){
                            helper?.setVisible(R.id.isHot,true)
                        }else{
                            helper?.setVisible(R.id.isHot,false)
                        }
                        helper?.setText(R.id.itemTime,item?.add_time)
                    }
                }
                recyclerView.adapter=adp
                recyclerView.layoutManager= LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL,false)
                adp.setOnItemClickListener { adapter, view, position ->
                    data[helper?.adapterPosition].list[position].click_rate= data[helper?.adapterPosition].list[position].click_rate+1
                    adp.notifyDataSetChanged()
                    val intent = Intent(mContext, SpecialDetailAty::class.java)
                    intent.putExtra("id",item?.list!![position].id)
                    intent.putExtra("tittle",item?.list[position].subject_name)
                    mContext.startActivity(intent)
                }

            }
        }
    }

/*
    fun setAdPlayer(gsyPlayer: StandardGSYVideoPlayer, viewGroup: ViewGroup?) {

        gsyPlayer.fullscreenButton.setOnClickListener {
            val fullVideo = gsyPlayer.startWindowFullscreen(mContext, false, true)
            fullVideo.backButton.setOnClickListener {
                Log.e("gsyfhp", "点到没有")
                AdHelper.hide()
                fullVideo.fullscreenButton.performClick()
            }
            fullVideo.startButton.setOnClickListener {
                Log.e("fhp", "播放状态${fullVideo.currentState}")
                if (fullVideo.currentState == GSYVideoView.CURRENT_STATE_NORMAL) {
                    fullVideo.startPlayLogic()
                    cp = 0
                } else if (fullVideo.currentState == GSYVideoView.CURRENT_STATE_PLAYING) {
                    fullVideo.onVideoPause()
                    cp = fullVideo.gsyVideoManager.currentPosition
                    var testUrl = ""
                    while (true) {
                        val index = (Math.random() * Constant.ads.size).toInt()
                        if (Constant.ads.get(index).is_show == 1) {
                            testUrl = Constant.ads.get(index).url
                            break
                        }
                    }
                    AdHelper.showAd(mContext, fullVideo.width / 3 * 2, gsyPlayer.height / 6 * 5, testUrl)
                } else if (fullVideo.currentState == GSYVideoView.CURRENT_STATE_PAUSE) {
                    Log.e("fhp", "播放器的管理器为空了？${fullVideo.gsyVideoManager == null}")
                    fullVideo.gsyVideoManager.start()
                    cp = 0
                } else if (fullVideo.currentState == GSYVideoView.CURRENT_STATE_AUTO_COMPLETE) {
                    fullVideo.startPlayLogic()
                    cp = 0
                }
            }
        }

        gsyPlayer.startButton.setOnClickListener {
            LOG.e("fhp", "此时的进度为${cp}播放状态为${gsyPlayer.currentState}")
            if (gsyPlayer.currentState == GSYVideoView.CURRENT_STATE_NORMAL) {
                gsyPlayer.seekOnStart = cp
                gsyPlayer.startPlayLogic()
                cp = 0
            } else if (gsyPlayer.currentState == GSYVideoView.CURRENT_STATE_PLAYING) {
                gsyPlayer.onVideoPause()
                cp = gsyPlayer.gsyVideoManager.currentPosition
                var testUrl = ""
                while (true) {
                    val index = (Math.random() * Constant.ads.size).toInt()
                    if (Constant.ads.get(index).is_show == 1) {
                        testUrl = Constant.ads.get(index).url
                        break
                    }
                }
                AdHelper.showAd(viewGroup!!, mContext, gsyPlayer.width / 3 * 2, gsyPlayer.height / 3 * 2, testUrl)
            } else if (gsyPlayer.currentState == GSYVideoView.CURRENT_STATE_PAUSE) {
                gsyPlayer.onVideoResume()
                cp = 0
            } else if (gsyPlayer.currentState == GSYVideoView.CURRENT_STATE_AUTO_COMPLETE) {
                gsyPlayer.startPlayLogic()
                cp = 0
            }


        }
    }*/

    private fun dp2px(context: Context, dpValue: Float): Int {
        val scale = context.getResources().getDisplayMetrics().density
        return (dpValue * scale + 0.5f).toInt()
    }
}